package com.example.carprovideruser.service.impl.hkf;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.carinterface.pojo.Brand;
import com.example.carinterface.pojo.CarModel;
import com.example.carinterface.pojo.CarParts;
import com.example.carinterface.pojo.RepairShop;
import com.example.carinterface.service.hkf.CarService;
import com.example.carinterface.utils.ResultJson;
import com.example.carprovideruser.mapper.hkf.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    CarMapper carMapper;

    @Override
    public ResultJson selectBrand() {
        ResultJson resultJson = new ResultJson();
        List<Brand> list = carMapper.selectBrand();
        return resultJson.setSuccess("查询成功", list);
    }

    @Override
    public ResultJson selectcarModel(Map map) {
        ResultJson resultJson = new ResultJson();
        List<CarModel> list = carMapper.selectcarModel(map);
        return resultJson.setSuccess("查询成功", list);
    }

    @Override
    public ResultJson selectCarPartsPrice(Map<String, Object> map) {
        ResultJson resultJson=new ResultJson();
        Integer carModelId = (Integer) map.get("carModelId");
        System.out.println(carModelId);
        List<Map> list = (List) map.get("list");
        Integer brandId = carMapper.selectBrandWithCarModle(carModelId);
        List<Map> repairShops = carMapper.selectRepairShopByBrandId(brandId);
        Double a = 0.0;
        List<Map> mapList=new ArrayList<>();
        Map<String,Object> stringObjectMap=new HashMap<>();
        for (Map repairShop : repairShops
                ) {
            Double discount = (Double) repairShop.get("discount");
            System.out.println(discount+"dwqdqwdqwdwq");
            for (Map map1 : list
                    ) {

                map1.put("carModelId", carModelId);
                System.out.println(carModelId);
                Double price = carMapper.selectCarPartsPrice(map1);
                Double realPrice=discount*price;
                map1.put("realprice",realPrice);
                a+=realPrice;
            }
            repairShop.put("list",list);
            repairShop.put("allprice",a);

        }
        return resultJson.setSuccess("成功",repairShops);
    }

    @Override
    public ResultJson selectCarParts(Integer carModelId) {
        ResultJson resultJson=new ResultJson();
        System.out.println(carModelId);
       List<Map> list=carMapper.selectCarParts(carModelId);

        return resultJson.setSuccess("成功",list);

    }
}